package com.hua.demo.edu.controller;


import com.alibaba.fastjson.JSON;
import com.hua.R;
import com.hua.demo.edu.entity.subject.OneSubject;
import com.hua.demo.edu.service.SubjectService;
import com.hua.demo.edu.service.impl.SubjectServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.print.DocFlavor;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author huazi
 * @since 2021-11-19
 */
@RestController
@RequestMapping("/edu/subject")
//@CrossOrigin
public class SubjectController {
    @Autowired
    private SubjectService subjectService;
    @Autowired
    private RedisTemplate redisTemplate;
//    添加课程分类
//    获取上传过来的文件，把文件内容读出来
    @PostMapping("addsubject")
    public R addsubject(MultipartFile file){
        subjectService.savesubject(file,subjectService);
        return R.ok();
    }

    //课程分类列表
    @GetMapping("getallsubject")
    public R getallsubject(){
        List<OneSubject> list= subjectService.getallonetwosubject();
        String name = redisTemplate.opsForValue().get("name").toString();
        System.out.println(name);

        System.out.println(name);

        return R.ok().data("list",list);
    }

}

